package org.liushengpei.com.controller;

import org.liushengpei.com.domain.GoodsAddress;
import org.liushengpei.com.service.IGoodsAddressService;
import org.liushengpei.com.util.result.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 收货地址控制器
 */
@RestController
@RequestMapping(value = "/goodsAddress")
public class GoodsAddressController {

    @Autowired
    private IGoodsAddressService goodsAddressService;

    /**
     * 添加收货地址
     *
     * @param address 收货地址对象
     */
    @PostMapping(value = "/addGoodsAddress")
    public ResultData addGoodsAddress(@RequestBody GoodsAddress address) {
        return ResultData.success(goodsAddressService.addGoodsAddress(address));
    }

    /**
     * 修改收货地址
     *
     * @param address 收货地址对象
     */
    @PostMapping(value = "/editGoodsAddress")
    public ResultData editGoodsAddress(@RequestBody GoodsAddress address) {
        return ResultData.success(goodsAddressService.editGoodsAddress(address));
    }

    /**
     * 查询所有收货地址
     *
     * @param userId 用户id
     */
    @GetMapping(value = "/getGoodsAddressList")
    public ResultData getGoodsAddressList(@RequestParam(value = "userId") String userId) {
        return ResultData.success(goodsAddressService.queryListByUserId(userId));
    }

    /**
     * 删除收货地址
     *
     * @param id 收货地址id
     */
    @GetMapping(value = "/delGoodsAddress")
    public ResultData delGoodsAddress(@RequestParam(value = "id") String id) {
        return ResultData.success(goodsAddressService.delOneById(id));
    }

    /**
     * 查询收货地址详细信息
     *
     * @param id 收货地址id
     */
    @GetMapping(value = "/queryDetail")
    public ResultData queryDetail(@RequestParam(value = "id") String id) {
        return ResultData.success(goodsAddressService.queryDetail(id));
    }

    /**
     * 修改默认地址选项
     *
     * @param id 收货地址id
     */
    @GetMapping(value = "/updateDefaultAddress")
    public ResultData updateDefaultAddress(@RequestParam(value = "id") String id, @RequestParam(value = "userId") String userId) {
        return ResultData.success(goodsAddressService.updateAddressTag(id, userId));
    }
}
